package com.kin207.netty.msg.decoder;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kin207.netty.util.ByteTools;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

public class HexMessageDecoder  extends ByteToMessageDecoder {
	final static Logger logger = LoggerFactory.getLogger(HexMessageEncoder.class);
		@Override
		protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
			//创建字节数组,buffer.readableBytes可读字节长度
	        byte[] b = new byte[in.readableBytes()];
	        //复制内容到字节数组b
	        in.readBytes(b);
	        //字节数组转字符串
	        out.add(ByteTools.bytesToHexString(b));
		}

}
